home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / etc / init.d / hwclock.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2006-10-12  |  3.5 KB  |  119 lines

  1. #!/bin/sh
  2. # hwclock.sh    Set and adjust the CMOS clock, according to the UTC
  3. #        setting in /etc/default/rcS (see also rcS(5)).
  4. #
  5. # Version:    @(#)hwclock.sh  2.00  14-Dec-1998  miquels@cistron.nl
  6. #
  7. # Patches:
  8. #        2000-01-30 Henrique M. Holschuh <hmh@rcm.org.br>
  9. #         - Minor cosmetic changes in an attempt to help new
  10. #           users notice something IS changing their clocks
  11. #           during startup/shutdown.
  12. #         - Added comments to alert users of hwclock issues
  13. #           and discourage tampering without proper doc reading.
  14.  
  15. # WARNING:    Please read /usr/share/doc/util-linux/README.Debian.hwclock
  16. #        before changing this file. You risk serious clock
  17. #        misbehaviour otherwise.
  18.  
  19. # Set this to any options you might need to give to hwclock, such
  20. # as machine hardware clock type for Alphas.
  21. HWCLOCKPARS=
  22.  
  23. hwclocksh()
  24. {
  25.     [ ! -x /sbin/hwclock ] && return 0
  26.     . /etc/default/rcS
  27.  
  28.     . /lib/lsb/init-functions
  29.  
  30.     [ "$GMT" = "-u" ] && UTC="yes"
  31.     case "$UTC" in
  32.        no|"")    GMT="--localtime"
  33.         UTC=""
  34.         ;;
  35.        yes)    GMT="--utc"
  36.         UTC="--utc"
  37.         ;;
  38.        *)    return 1 ;;
  39.     esac
  40.  
  41.     case "$BADYEAR" in
  42.        no|"")    BADYEAR="" ;;
  43.        yes)    BADYEAR="--badyear" ;;
  44.        *)    return 1 ;;
  45.     esac
  46.  
  47.     case "$1" in
  48.     start)
  49.         if [ ! -f /etc/adjtime ] && [ ! -e /etc/adjtime ]; then
  50.         echo "0.0 0 0.0" > /etc/adjtime
  51.         fi
  52.  
  53.         # Uncomment the hwclock --adjust line below if you want
  54.         # hwclock to try to correct systematic drift errors in the
  55.         # Hardware Clock.
  56.         #
  57.         # WARNING: If you uncomment this option, you must either make
  58.         # sure *nothing* changes the Hardware Clock other than
  59.         # hwclock --systohc, or you must delete /etc/adjtime
  60.         # every time someone else modifies the Hardware Clock.
  61.         #
  62.         # Common "vilains" are: ntp, MS Windows, the BIOS Setup
  63.         # program.
  64.         #
  65.         # WARNING: You must remember to invalidate (delete)
  66.         # /etc/adjtime if you ever need to set the system clock
  67.         # to a very different value and hwclock --adjust is being
  68.         # used.
  69.         #
  70.         # Please read /usr/share/doc/util-linux/README.Debian.hwclock
  71.         # before enablig hwclock --adjust.
  72.  
  73.         #hwclock --adjust $GMT $BADYEAR
  74.         :
  75.  
  76.         if [ "$HWCLOCKACCESS" != no ]; then
  77.         # Copies Hardware Clock time to System Clock using the correct
  78.         # timezone for hardware clocks in local time, and sets kernel
  79.         # timezone. DO NOT REMOVE.
  80.         /sbin/hwclock --hctosys $GMT $HWCLOCKPARS $BADYEAR
  81.  
  82.         if /sbin/hwclock --show $GMT $HWCLOCKPARS $BADYEAR 2>&1 > /dev/null |
  83.             grep -q '^The Hardware Clock registers contain values that are either invalid'; then
  84.             echo "Invalid system date -- setting to 1/1/2002"
  85.             /sbin/hwclock --set --date '1/1/2002 00:00:00' $GMT $HWCLOCKPARS $BADYEAR
  86.         fi
  87.         fi
  88.         ;;
  89.     stop|restart|reload|force-reload)
  90.         #
  91.         # Updates the Hardware Clock with the System Clock time.
  92.         # This will *override* any changes made to the Hardware Clock.
  93.         #
  94.         # WARNING: If you disable this, any changes to the system
  95.         #          clock will not be carried across reboots.
  96.         #
  97.         if [ "$HWCLOCKACCESS" != no ]; then
  98.         if [ "$GMT" = "-u" ]; then
  99.             GMT="--utc"
  100.         fi
  101.         /sbin/hwclock --systohc $GMT $HWCLOCKPARS $BADYEAR
  102.         fi
  103.         ;;
  104.     show)
  105.         if [ "$HWCLOCKACCESS" != no ]; then
  106.         /sbin/hwclock --show $GMT $HWCLOCKPARS $BADYEAR
  107.         fi
  108.         ;;
  109.     *)
  110.         log_success_msg "Usage: hwclock.sh {start|stop|reload|force-reload|show}"
  111.         log_success_msg "       start sets kernel (system) clock from hardware (RTC) clock"
  112.         log_success_msg "       stop and reload set hardware (RTC) clock from kernel (system) clock"
  113.         return 1
  114.         ;;
  115.     esac
  116. }
  117.  
  118. hwclocksh "$@" &
  119.